﻿$(function(){//延迟加载
	var parentname=$('#parentname').val();
	var parentId=$('#parentId').val();
	var parentlevel=$('#parentlevel').val();
	$('#addnewdp').propertygrid({
		width:'310px',
		data:{"total":4,"rows":[    
		    	                  {'name':'上级部门','value':parentname,'group':'ID Settings','editor':{
		    	                	  'editable':false
		    	                  }},
		    	                  {"name":"部门名称","group":"ID Settings","editor":{    
		    	                      "type":"validatebox",    
		    	                      "options":{    
		    	                      "required":true   
		    	                     }    
		    	                  }},
		    	                  {"name":"部门地址","group":"ID Settings","editor":"text"},    
		    	                  {"name":"部门电话","group":"ID Settings","editor":"text"},
		    	                  {"name":"部门职位","group":"ID Settings","editor":{
		    	                	  type:'combobox',
		    	                	  options:{
		  								valueField:'roleId',
		  								textField:'rolename',
		  								method:'get',
		  								url:'getroles',
		  								multiple:true,
		  								required:true
		  							}
		    	                  }}
		    	              ]},
		columns:[[
		         {'field':'name','title':'新部门','width':'120px'},
		         {'field':'value','title':'','width':'170px'}		          		          
		          ]],
		//showHeader:false		    	              
	});
	
	$('#addcompl').linkbutton({
		plain:true,
		iconCls:'icon-ok',
		onClick:function(){
			var dploc=$('#addnewdp').propertygrid('getRows')[2].value;
			if(dploc==undefined)dploc='';
			var dptel=$('#addnewdp').propertygrid('getRows')[3].value;
			if(dptel==undefined)dptel='';
			var dpname=$('#addnewdp').propertygrid('getRows')[1].value;
			
			var roleIds=$('#addnewdp').propertygrid('getRows')[4].value;
			//alert(dpname);
//			if(!$('#ad').form('validate')){
//				alert('信息不完整!');
//			}
//			if(!$('#ad').form('validate')){
//				return 0;
//			}	
			$.ajax({
				url:'adddepartment',
				type:'POST',
				data:{
					parentId:parentId,
					parentname:parentname,
					parentlevel:parentlevel,
					dploc:dploc,
					dptel:dptel,
					dpname:dpname,
					roles:roleIds
				},				
				success:function(data){
					alert(data.msg);
				}
			});
		}
	});
	
})